public class Multiply {

    public String multiply(String num1, String num2) {
        if (num1.length() > num2.length()) return multiply(num2, num1);
        String temp = num2;
        for (int i = 0; i < num1.length(); i++) {
            temp = process(temp);
        }
        return "";
    }

    public String process(String num1) {
        StringBuffer stringBuffer = new StringBuffer(num1);
        String reverse = stringBuffer.reverse().toString();
        int n = reverse.length();
        StringBuffer ans = new StringBuffer();
        boolean flag = false;
        for (int i = 0; i < n; i++) {
            char c = reverse.charAt(i);
            if (c + c >= 57) {
                if (flag) {
                    if (c + c == 57) {
                        ans.append(0);
                    } else {
                        ans.append((char) (c + c - 58 + 1));
                    }
                    flag = true;
                } else {
                    if (c + c == 57) {
                        ans.append(9);
                    } else {
                        ans.append((char) (c + c - 58));
                        flag = true;
                    }
                }
            } else {
                if (flag) {
                    ans.append((char) (c + c + 1));
                    flag = false;
                } else {
                    ans.append((char) (c + c));
                }
            }
        }
        if (flag) {
            ans.append(1);
        }
        return ans.reverse().toString();
    }
}
